/**
 * 
 */
package com.ydy.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ydy.annotation.AdminToken;
import com.ydy.annotation.CheckFormRepeat;
import com.ydy.annotation.CtrlParam;
import com.ydy.annotation.StaffToken;
import com.ydy.controller.base.BaseController;
import com.ydy.model.Account;
import com.ydy.service.account.AccountService;
import com.ydy.utils.StringUtils;
import com.ydy.vo.other.BaseVo;
import com.ydy.vo.other.PageVo;

/**
 * @author xuzhaojie
 *
 *         2019年1月18日 上午9:17:29
 */
@Controller
@RequestMapping(value = "account", name = "实名账户模块")
public class AccountController extends BaseController {

	@Autowired
	private AccountService accountService;

	@AdminToken
	@GetMapping(value = "selectByAdmin", name = "管理员筛选实名账户")
	@ResponseBody
	public ResponseEntity<PageVo<Account>> selectByAdmin(Account account, Integer page, Integer size) {
		StringUtils.setParamEmptyToNull(account);
		PageVo<Account> vo = accountService.select(account, page, size);
		return ResponseEntity.ok(vo);
	}

	@StaffToken
	@GetMapping(value = "select", name = "店员筛选实名账户")
	@ResponseBody
	public ResponseEntity<PageVo<Account>> select(Account account, Integer page, Integer size) {
		StringUtils.setParamEmptyToNull(account);
		account.setShopId(getStaff().getShopId());
		PageVo<Account> vo = accountService.select(account, page, size);
		return ResponseEntity.ok(vo);
	}

	@StaffToken
	@CheckFormRepeat
	@PostMapping(value = "save", name = "店员保存实名账户")
	@ResponseBody
	public ResponseEntity<Account> save(Account account) {
		account.setShopId(getStaff().getShopId());
		return ResponseEntity.ok(accountService.saveOrUpdate(account, null));
	}

	@StaffToken
	@CheckFormRepeat
	@PostMapping(value = "setDefault", name = "店员设置默认实名账户")
	@ResponseBody
	public ResponseEntity<BaseVo> setDefault(@CtrlParam("id") Long id) {
		return ResponseEntity.ok(accountService.setDefault(id, getStaff()));
	}

	@StaffToken
	@CheckFormRepeat
	@DeleteMapping(value = "delete", name = "店员删除实名账户")
	@ResponseBody
	public ResponseEntity<BaseVo> delete(@CtrlParam("id") Long id) {
		return ResponseEntity.ok(accountService.delete(id, getStaff()));
	}

	@StaffToken
	@GetMapping(value = "selectById", name = "店员查看实名账户信息")
	@ResponseBody
	public ResponseEntity<Account> selectById(@CtrlParam("id") Long id) {
		return ResponseEntity.ok(accountService.selectById(id, getStaff()));
	}

	@AdminToken
	@GetMapping(value = "selectByIdByAdmin", name = "管理员查看实名账户信息")
	@ResponseBody
	public ResponseEntity<Account> selectByIdByAdmin(@CtrlParam("id") Long id) {
		return ResponseEntity.ok(accountService.selectById(id, null));
	}
}